<?php

namespace App\Http\Controllers;

use App\Models\Zhanghu;
use Illuminate\Http\Request;

class Login extends Controller
{
    //
    public function index(){
        $data = \request()->post();
        $model = Zhanghu::where('uname',$data['user'])->first();
        if (empty($model)){
            return [
                'code'=>1,
                'msg'=>'用户名错误',
                'data'=>[]
            ];
        }elseif ($data['password']!=$model['password']){
            return [
                'code'=>1,
                'msg'=>'密码错误',
                'data'=>[]
            ];
        }
        session('user',$model);
        return [
            'code'=>200,
            'msg'=>'登录成功',
            'data'=>[]
        ];
    }
}
